import Vue from 'vue'
import App from './App.vue'
import router from './router'

/* Vue.config.productionTip = false

new Vue({
  router,
  render: h => h(App)
}).$mount('#app') */

let instance = null
function render(){
  instance = new Vue({
    router,
    render: h => h(App)
  }).$mount('#app') // 这里挂载到自己的html中，基座会拿到这个挂载后的html，将其插入进去
}

// 动态添加publicPath
if(window.__POWERED_BY_QIANKUN__){
  __webpack_public_path__ = window.__INJECTED_PUBLIC_PATH_BY_QIANKUN__;
}

// 默认独立运行
if (!window.__POWERED_BY_QIANKUN__) {
  render();
}

// 子组件协议 bootstrap mount unmount
export async function bootstrap(props){
  
  Vue.prototype.isQianKun = props.isQianKun
  Array.isArray(props.prototype) && 
  props.prototype.map(pty => {
    Vue.prototype[pty.name] = pty.value
  })

  console.log('vue bootstrap props', props)
  console.log(`主基座num的值是${props.data.state.num}, ${props.utils.prototype.hello('vue')}`)
}

export async function mount(props){
  render(props)
}

export async function unmount(props){
  instance.$destroy()
}